import { useCallback } from 'react'
import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux'
import type { AppState, AppDispatch } from '../index'
import {
    changeLoading
} from './actions';

export const useAppSelector: TypedUseSelectorHook<AppState> = useSelector

/**
 * 改变loading状态
 */
export const useChangeLoading = () => {
    const dispatch = useDispatch<AppDispatch>()

    return useCallback(
        (loading: boolean) => {
            dispatch(changeLoading({ loading }))
        },
        [dispatch]
    )
}



/**
 * 获取loading状态
 */
export const useLoading = () => {
    const value = useAppSelector(state => state.common.loading)
    return value
}